<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../baselayout/import.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="${staticPath}/assets/css/bootstrap.min.css">
<link rel="stylesheet" href="${staticPath}/assets/css/fp-admin.css">
<title>特征工程</title>
<style>
td{
width:25%;
}

</style>
</head>
<body>
<div class="fp-header">
	<h1>数据集详情</h1>
</div>
<table class="table">
      <caption>文档类别数目表,共有${totalDoc}文档</caption>
      <thead>
        <tr>
          <th>#</th>
          <th>类别</th>
          <th>文档数量</th>

         <th>操作</th>
        </tr>
      </thead>
      <tbody>
		<c:forEach items="${eachClassCount}" var = "it" varStatus = "idx">
			<tr>
	          <th scope="row">${idx.index + 1 }</th>
	          <td class="lb"><c:out value="${it.key}" /> </td>
	          <td><c:out value="${it.value}" /> </td>
	          <td><button onclick="upload(this)" class="btn btn-default">上传该分类新数据文件</button><button onclick="del(this)" class="btn btn-default">删除该分类</button></td>
	        </tr>
		</c:forEach>   
		<tr>
			<td colspan="5" class="text-center">
				<button type="button" id="tip" onclick="addNewClass('mkdir')" class="btn no-bg btn-contact">添加分类</button>
				<button type="button" id="tip" onclick="window.location.reload()" class="btn no-bg btn-contact">刷新</button>
			</td>
		</tr>
      </tbody>
</table>
<div id="fileArea" style="display:none">
<label id="fn"></label><button onclick="submitForm()">提交</button>
</div>
    <script src="${staticPath}/js/jQuery-1.9.1.js"></script>
    <script src="${staticPath}/js/bootstrap.min.js"></script>
    <script src="${staticPath}/js/my.js"></script>
    <script>
    function submitForm(){
    	$("#upload input[type=submit]").click();
    	$("#fileArea").css('display','none');
    }
    function del(btn){
    	var subdir = $(btn).parent().siblings(".lb").html().trim();
		if(/^c\d{1,2}$/.test(subdir)){
			$.ajax({
				url:"./handlefs.do",
				type:'post',
				data:{"action":"rmdir","arg":subdir},
				success:function(data){alert(data)},
				error:function(e){alert(e)}
			})
		}
    }
    function addNewClass(action){
		$('#myModal').modal('show');
	}
    function upload(btn){
		var subdir = $(btn).parent().siblings(".lb").html().trim();
		if(/^c\d{1,2}$/.test(subdir)){
			$("#upload input[name=subdir]").val(subdir);
			$("#upload input[type=file]").click();
		
		}else{
			return false;
		}

	}
	function change(btn){
		var file = $(btn).val();
		if(typeof file == 'string' && file.length>0){
			//$("#upload input[type=submit]").click();
			$("#fn").html(file);
			$("#fileArea").css('display','block');
		}
	}
    
    $(document).ready(function(){
		!function(w){
    		$('#myModal').on('hidden.bs.modal', function (e) {
    			div = e.currentTarget;
    			var value = $("#param",div).val().trim();
    			if(/c\d{1,2}$/.test(value)){
    		
    				$.ajax({
    					url:"./handlefs.do",
    					type:'post',
    					data:{"action":"mkdir","arg":value},
    					success:function(data){alert(data)},
    					error:function(e){alert(e)}
    				})
    			}	
    		});
    		
    	}(window)
		
	});
	
    
    </script>
    
         
 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">请输入类名</h4>
      </div>
      <div class="modal-body">
        <input id="param" type="text" class="form-control">
      </div>
      <div class="modal-footer">
        <button type="button" onclick="$('#myModal').modal('hide');" class="btn btn-primary">确认</button>
      </div>
    </div>
  </div>
</div>

<form id="upload" style="display:none"  action="./upload.do" method="post" enctype="multipart/form-data">
 <input type="file" name="file" onchange="change(this)">
 <input type="hidden" name="subdir" value="">
 <input type="submit">
 
</form> 

</body>
</html>